from demo_unittest.unittest_base.calculator import Count
import unittest
import HTMLTestRunner


class TestCount(unittest.TestCase):
    # 测试的初始化
    def setUp(self):
        print("test start")
        # a = 0.3214323
        # print("%.2f%%" % (a * 100))

    # 测试的回收-测试的环境还原, 测试数据的清理
    def tearDown(self):
        print("test end")

    # 测试用例add的编写
    def test_add(self):
        self.Count = Count(2, 5)
        self.assertEqual(self.Count.add(), 7, 'Failed')

    # 测试用例sub的编写
    def test_sub(self):
        self.Count = Count(6, 3)
        self.assertEqual(self.Count.sub(), 3)

    # 测试用例mul的编写
    def test_mul(self):
        self.Count = Count(6, 3)
        self.assertEqual(self.Count.mul(), 18)

    # 测试用例div的编写
    def test_div(self):
        self.Count = Count(6, 3)
        self.assertEqual(self.Count.div(), 2)


if __name__ == "__main__":
    suite = unittest.TestSuite()
    #
    # tescases1 = unittest.TestLoader().loadTestsFromTestCase(TestCount)  #添加类名
    # suite.addTest(tescases1)
    #
    # #无测试报告
    # runner = unittest.TextTestRunner(verbosity=2)
    # runner.run(suite)

    # 定义个报告存放路径，支持相对路径。
    # filename = 'result.html'
    fp = open('result.html', 'wb')

    runner = HTMLTestRunner.HTMLTestRunner(
        stream=fp,
        title=u'接口测试测试报告',
        description=u'用例执行情况：')
    # 执行测试用例
    runner.run(suite)
    fp.close()
